#ifndef __SERVER_H__
#define __SERVER_H__

#include <boost/asio.hpp>
#include <map>
#include <mutex>
#include <memory.h>

#include "session.h"

class Server
{
public:
    using Acceptor = boost::asio::ip::tcp::acceptor;
    using Tcp = boost::asio::ip::tcp;
    using IOContext = boost::asio::io_context;

    Server(IOContext& io_context, const uint16_t port);
    ~Server();

    void delete_session(const std::string& id);

private:

    void start_accept();

    void handle_accept(Session::ptr session, const boost::system::error_code& error);   

private:
    IOContext& _io_context;
    uint16_t _port;
    Acceptor _acceptor;
    std::map<std::string, Session::ptr> _sessions;
    std::mutex _sessions_lock;
};




#endif // !__SERVER_H__
